package cn.xfdzx.android.apps.shop.activity.remake;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.remake.MyRemakeActivity;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;
import cn.xfdzx.android.apps.shop.util.ProgressDialog;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;

/*
/* 零售订单评价页面
 */
public class OrderRemakeFinishActivity extends BaseMvpActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;      //标题栏-左边按钮
    @BindView(R.id.tv_lookremake)
    TextView tv_lookremake;    //批发查看评价
    @BindView(R.id.rl_remake_retail)
    RelativeLayout rl_remake_retail;    //零售评价完成布局
    @BindView(R.id.rl_remake_market)
    RelativeLayout rl_remake_market;    //批发评价完成布局
    @BindView(R.id.rl_remake_ps)
    RelativeLayout rl_remake_ps;    //零售配送评价完成布局
    @BindView(R.id.rl_remake_zt)
    RelativeLayout rl_remake_zt;    //零售自提评价完成布局
    @BindView(R.id.ll_state)
    LinearLayout llState;   //
    @BindView(R.id.img_store)
    ImageView img_store;   //店铺头像
    @BindView(R.id.tv_qishouremake)
    TextView tv_qishouremake;   //骑手评价
    @BindView(R.id.star01)
    ImageView star01;   //总体评分星星
    @BindView(R.id.star02)
    ImageView star02;   //总体评分星星
    @BindView(R.id.star03)
    ImageView star03;   //总体评分星星
    @BindView(R.id.star04)
    ImageView star04;   //总体评分星星
    @BindView(R.id.star05)
    ImageView star05;   //总体评分星星
    @BindView(R.id.star01_zt)
    ImageView star01_zt;   //自提评分星星
    @BindView(R.id.star02_zt)
    ImageView star02_zt;   //自提评分星星
    @BindView(R.id.star03_zt)
    ImageView star03_zt;   //自提评分星星
    @BindView(R.id.star04_zt)
    ImageView star04_zt;   //自提评分星星
    @BindView(R.id.star05_zt)
    ImageView star05_zt;   //自提评分星星

    private RelativeLayout.LayoutParams item_bar;
    private String pageType;
    private String shopimg;
    private int qishouremake;
    private int starnum;
    @Override
    public int getLayoutId() {
        return R.layout.activity_remakefinish;
    }

    @Override
    public void initView() {
        initHigh();
        pageType =  getIntent().getStringExtra("pageType");
        shopimg =  getIntent().getStringExtra("shopimg");
        qishouremake =  getIntent().getIntExtra("qishouremake",0);
        starnum =  getIntent().getIntExtra("starnum",0);

        //1-零售配送 ，2零售自提，3批发
        if (pageType.equals("1")){
            rl_remake_market.setVisibility(View.GONE);
            rl_remake_retail.setVisibility(View.VISIBLE);
            rl_remake_ps.setVisibility(View.VISIBLE);
            rl_remake_zt.setVisibility(View.GONE);
            if (qishouremake==2){
                tv_qishouremake.setText("不满意");
            }else {
                tv_qishouremake.setText("满意");
            }
            setStarState(star01,star02,star03,star04,star05);
            ImageGlideUtil.loadImage(this,img_store,shopimg);
        }else if (pageType.equals("2")){
            rl_remake_market.setVisibility(View.GONE);
            rl_remake_retail.setVisibility(View.VISIBLE);
            rl_remake_ps.setVisibility(View.GONE);
            rl_remake_zt.setVisibility(View.VISIBLE);
            setStarState(star01_zt,star02_zt,star03_zt,star04_zt,star05_zt);
        }else if (pageType.equals("3")){
            rl_remake_market.setVisibility(View.VISIBLE);
            rl_remake_retail.setVisibility(View.GONE);
            rl_remake_ps.setVisibility(View.GONE);
            rl_remake_zt.setVisibility(View.GONE);
        }

    }

    private void setStarState(ImageView img_star1,ImageView img_star2,ImageView img_star3,
                              ImageView img_star4,ImageView img_star5) {
        switch (starnum+""){
            case "1":
                img_star1.setImageResource(R.drawable.ic_staryellow);
                break;
            case "2":
                img_star1.setImageResource(R.drawable.ic_staryellow);
                img_star2.setImageResource(R.drawable.ic_staryellow);
                break;
            case "3":
                img_star1.setImageResource(R.drawable.ic_staryellow);
                img_star2.setImageResource(R.drawable.ic_staryellow);
                img_star3.setImageResource(R.drawable.ic_staryellow);
                break;
            case "4":
                img_star1.setImageResource(R.drawable.ic_staryellow);
                img_star2.setImageResource(R.drawable.ic_staryellow);
                img_star3.setImageResource(R.drawable.ic_staryellow);
                img_star4.setImageResource(R.drawable.ic_staryellow);

                break;
            case "5":
                img_star1.setImageResource(R.drawable.ic_staryellow);
                img_star2.setImageResource(R.drawable.ic_staryellow);
                img_star3.setImageResource(R.drawable.ic_staryellow);
                img_star4.setImageResource(R.drawable.ic_staryellow);
                img_star5.setImageResource(R.drawable.ic_staryellow);
                break;
        }
    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }

    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);
        llState.setBackgroundColor(getResources().getColor(R.color.color_F2F2F2));
    }


    @Override
    public void showLoading() {
        if (!ProgressDialog.getInstance().materialDialog.isShowing()) {
            ProgressDialog.getInstance().show(this);
        }
    }

    @Override
    public void hideLoading() {
        ProgressDialog.getInstance().dismiss();
    }

    @Override
    public void onError(Throwable throwable) {

    }

    @OnClick({R.id.iv_back,R.id.tv_lookremake})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:    //返回按钮点击
                finish();
                break;
            case R.id.tv_lookremake:    //查看评价
                Intent intent = new Intent(this, MyRemakeActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
